package org.hackystat.ambientdevice.device.orb;

import java.util.logging.Logger;
import org.hackystat.ambientdevice.ConfigurationException;
import org.hackystat.ambientdevice.device.AmbientAction;
import org.hackystat.ambientdevice.device.orb.AmbientOrb.Animation;
import org.hackystat.utilities.logger.HackystatLogger;

/**
 * Class that implement AmbientAction to change the AmbientOrb's Animation.
 * 
 * @author Shaoxuan Zhang
 */
public class ChangeAnimation implements AmbientAction {

  /** the AmbientOrb that will change Animation. */
  private AmbientOrb orb;
  /** the Animation it will be. */
  private Animation animation = null;
  /** The logger for logging. */
  private Logger logger = HackystatLogger.getLogger("org.hackystat.ambientdevice");
  
  /**
   * Constructor.
   * 
   * @param orb an AmbientOrb
   * @param animation an Animation
   * @throws ConfigurationException for some errors
   */
  public ChangeAnimation(AmbientOrb orb, String animation) throws ConfigurationException {
    this.orb = orb;
    this.animation = Animation.getEnumValue(animation);
    if (this.animation == Animation.Unsupported) {
      throw new ConfigurationException("Animation " + animation + 
          " is not supported by AmbientOrb");
    }
  }
  
  /**
   * Change the Orb's animation according to the data within this object.
   */
  public void act() {
    logger.info("Change AmbientOrb's Animation to " + animation);
    this.orb.setAnim(animation);
    this.orb.updateState();
  }

  /**
   * @return the AmbientOrb
   */
  public AmbientOrb getAmbientOrb() {
    return this.orb;
  }

  /**
   * @return the Animation
   */
  public Animation getAnimation() {
    return this.animation;
  }
}
